<h1 class="title-h1">设置顺丰差价</h1>

<div class="layui-card-body">
        
    {if condition="(count($list)==0)"}
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" data-type="add">添加规则</button>
    </div>
    {/if}

    <table class="layui-table" id="dataTable" lay-filter="dataTable">
        <thead>
            <tr>
                <th>规则名称</th>
                <th>配送地区</th>
                <th>首重（0~1.1Kg）</th>
                <th>续重（每超出1Kg）</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {volist name="list" id="vo" key="index"}
            <tr data-id="{$vo.id}">
                <td colspan="5" style="border:none;"></td>
            </tr>
            <tr data-id="{$vo.id}">
                <td rowspan="{$vo.table|count}">{$vo.name}</td>
                {volist name="vo.table" id="v" key="k"}
                {$k!=1?'<tr data-id='.$vo.id.'>':''}
                <td>{$v.area}</td>
                <td>{$v.first_weight}</td>
                <td>{$v.continue_weight}</td>
                {if condition="($k == 1)"}
                <td rowspan="{$vo.table|count}">
                    <a class="layui-btn layui-btn-xs" data-type="edit" data-id="{$vo.id}">编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" data-type="del" data-id="{$vo.id}">删除</a>
                </td>
                {/if}
            </tr>
            {/volist}
            {/volist}
        </tbody>
    </table>
</div>
<script>
    layui.use(['table', 'http', 'form'], function () {
        var table = layui.table,
            layer = layui.layer,
            http = layui.http,
            $ = layui.$;
        var form = layui.form;

        $('.layui-btn').on('click', function () {
            var type = $(this).data('type')
            var id = $(this).data('id')
            switch (type) {
                case 'edit':
                    editFunc(id)
                    break;
                case 'add':
                    editFunc()
                    break;
                case 'del':
                    layer.confirm('真的删除这条数据吗?', {
                        skin: 'layui-layer-admin',
                    }, function (index) {
                        http.post('/postage/del', {
                            id: id
                        }, function (res) {
                            $("tr[data-id="+id+"]").remove()
                            layer.close(index);
                        })
                    });
                    break;
            }
        });
        var editFunc = function (id) {
            http.get('/postage/edit?id=' + id,id ? '编辑邮费' : '添加邮费', '700px');            
        }

    });
</script>